package analysis

import (
	"bytes"
	"compress/bzip2"
	"errors"
	"os"
	"strings"

	"gitee.com/yejia/radar/model"
)

// 解析zip文件
func Parse(radar_path string) (*model.RadarWrapper, error) {
	data, err := os.ReadFile(radar_path)
	if err != nil {
		return nil, err
	}
	if strings.HasSuffix(radar_path, ".bz2") {
		return ParseBzip2(data)
	} else if strings.HasSuffix(radar_path, ".bin") {
		return ParseBin(data)
	}
	return nil, errors.New("suffix are neither .bz2 nor .bin")
}

// 解析bz结尾的文件，接收byte数组
func ParseBzip2(data []byte) (*model.RadarWrapper, error) {
	reader := bzip2.NewReader(bytes.NewReader(data))
	return parseBin(reader)
}
